package com.zheng.study.company.dao.impl;

import com.zheng.study.base.dao.impl.BaseDaoImpl;
import com.zheng.study.company.dao.AdminDao;
import com.zheng.study.company.entity.Admin;
import org.springframework.stereotype.Repository;
import org.springframework.util.Assert;

/**
 * newFile
 * ============================================================================
 * author : dzw
 * createDate:  2018/8/16 。
 * ============================================================================
 */
@Repository
public class AdminDaoImpl extends BaseDaoImpl<Admin, String> implements AdminDao {

	public Admin getAdminByAccount(String account) {
		Assert.hasText(account, "account 不能为空");
		String hql = "from " + Admin.class.getName() + " a where a.username = :account or a.userMobile = :account or a.userEmail = :account";
		Admin admin = null;
		try {
			admin = (Admin) getSession().createQuery(hql).setParameter("account", account).uniqueResult();
		}catch (Exception e){
			e.printStackTrace();
		}
		return admin;
	}

	public Admin getAdminByOpenId(String openId) {
		Assert.hasText(openId, "openId 不能为空");
		String hql = "from " + Admin.class.getName() + " a where a.openId = :openId";
		return (Admin) getSession().createQuery(hql).setParameter("openId", openId).uniqueResult();
	}

}
